import sys
from PyQt5.QtWidgets import QPushButton, QWidget, QApplication, \
    QDesktopWidget, QMessageBox
from PyQt5.QtGui import QIcon, QPalette, QBrush, QPixmap
from PyQt5.QtCore import pyqtSignal


class function(QWidget):
    s1 = pyqtSignal()
    s2 = pyqtSignal()
    s3 = pyqtSignal()
    s4 = pyqtSignal()
    s5 = pyqtSignal()

    def borrow(self):
        self.s1.emit()

    def back(self):
        self.s2.emit()

    def history(self):
        self.s3.emit()

    def orgnize(self):
        self.s4.emit()

    def rt(self):
        self.s5.emit()

    def __init__(self):
        super().__init__()

    def initUI(self):
        self.bt1 = QPushButton('借阅图书', self)
        self.bt2 = QPushButton('归还图书', self)
        self.bt3 = QPushButton('历史借阅', self)
        self.bt4 = QPushButton('管理图书', self)
        self.bt5 = QPushButton('返回', self)
        self.bt6 = QPushButton('退出', self)

        self.bt1.setGeometry(80, 50, 240, 50)
        self.bt2.setGeometry(80, 140, 240, 50)
        self.bt3.setGeometry(80, 230, 240, 50)
        self.bt4.setGeometry(80, 320, 240, 50)
        self.bt5.setGeometry(100, 410, 80, 40)
        self.bt6.setGeometry(220, 410, 80, 40)

        self.bt1.clicked.connect(self.borrow)
        self.bt2.clicked.connect(self.back)
        self.bt3.clicked.connect(self.history)
        self.bt4.clicked.connect(self.orgnize)
        self.bt5.clicked.connect(self.rt)
        self.bt6.clicked.connect(QApplication.instance().quit)

        bp = QPalette()
        bp.setBrush(self.backgroundRole(), QBrush(QPixmap('bk2.jpg')))
        self.setPalette(bp)

        self.resize(400, 500)
        self.setWindowTitle('功能选择')
        self.setWindowIcon(QIcon('icon.png'))
        self.show()

    def center(self):
        x = self.frameGeometry()
        y = QDesktopWidget().availableGeometry().center()
        x.moveCenter(y)
        self.move(x.topLeft())

    # def closeEvent(self, event):
    #     qt = QMessageBox(QMessageBox.Question, "系统提示", "是否退出")
    #     yap = qt.addButton("是", QMessageBox.YesRole)
    #     qt.addButton("否", QMessageBox.NoRole)
    #     qt.setWindowIcon(QIcon('Icon.png'))
    #     qt.exec_()
    #     if qt.clickedButton() == yap:
    #         event.accept()
    #     else:
    #         event.ignore()


if __name__ == '__main__':
    app = QApplication(sys.argv)
    a = function()
    a.initUI()
    sys.exit(app.exec_())
